package org.rcgwt.client.ui.validator.impl;

import org.rcgwt.client.ui.validator.IClientValidatorContext;
import org.rcgwt.client.ui.validator.ISingleton;
import org.rcgwt.client.ui.validator.ITranslator;
import org.rcgwt.client.ui.validator.IValidatorElement;

/**
 * A translator which translate accent character in simple character (é ==> e)
 * with its unicode representation
 * 
 * @author Elian ORIOU
 * 
 */

public class RemoveAccentTranslator implements ITranslator, ISingleton {

	private static final RemoveAccentTranslator INSTANCE = new RemoveAccentTranslator();

	protected RemoveAccentTranslator() {

	}

	@Override
	public char translate(IClientValidatorContext context, char f) {
		switch (f) // Unicode value
		{
		case 232: // é
		case 233: // è
		case 234: // ê
		case 235: // ë
			return 'e';
		case 224: // à
		case 226: // â
		case 228: // ä
			return 'a';
		case 249: // ù
		case 251: // û
		case 252: // ü
			return 'u';
		case 238: // î
		case 239: // ï
			return 'i';
		case 244: // ô
		case 246: // ö
			return 'o';
		case 255: // ÿ
			return 'y';
		default:
			return f;
		}
	}

	public static IValidatorElement getInstance() {
		return INSTANCE;
	}
}